package ar.edu.itba.pod.Legajo47342.communication.handlers;

import java.rmi.RemoteException;

import ar.edu.itba.pod.Legajo47342.Node;
import ar.edu.itba.pod.simul.communication.Message;
import ar.edu.itba.pod.simul.communication.payload.DisconnectPayload;

public class DisconnectHandler implements Handler {

	private Node node;
	
	public DisconnectHandler(Node node) {
		super();
		this.node = node;
	}
	
	@Override
	public void handle(Message message) {
		DisconnectPayload disPayLoad = (DisconnectPayload) message.getPayload();
		node.getLoads().remove(disPayLoad.getDisconnectedNodeId());
		System.out.println("BORRE? "+node.getClusterNodes().remove(disPayLoad.getDisconnectedNodeId()));
		
		System.out.println("Aviso que se va "+disPayLoad.getDisconnectedNodeId());
		try {
			node.getManager().getGroupCommunication().broadcast(message);
		} catch (RemoteException e) {
			e.printStackTrace();
		}

	}

}
